package gatperdut.chato.core.interpreter.actions;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.constants.CSConstantsString;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.interpreter.actions.generic.Action;
import gatperdut.chato.core.interpreter.grammar.comminfo.StatusInfo;

public class StatusAction extends Action {

    public StatusAction( StatusInfo info, BaseController entityController ) {
        super( info, entityController );
    }

    @Override
    public CommandExecutionResult perform() {
        checkForRunningCraft();

        StringBuilder sb = new StringBuilder();

        // --combat status
        if ( getEntityController().getCombatController().isInCombat() ) {
            // --attackers
            if ( getEntityController().getCombatController().isBeingAttacked() ) {
                sb.append( "You are being attacked by " + getEntityController().getCombatController().getCombatThread().listAttackersShortDescription() + "." );
            }
            else {
                sb.append( "You are not currently being attacked." );
            }
            sb.append( CSConstantsString.NEWLINE );
            // --target
            if ( getEntityController().getCombatController().getTarget() != null ) {
                sb.append( "You are attacking " + getEntityController().getCombatController().getTarget().getCharacter().getShortDesc() + "." );
            }
            else {
                sb.append( "You are not fighting back." );
            }
            sb.append( CSConstantsString.NEWLINE );
            // --fleeing?
            if ( getEntityController().getCombatController().isFleeing() ) {
                sb.append( "You are trying to flee." );
            }
            else {
                sb.append( "You are not currently fleeing." );
            }
        }
        else {
            sb.append( "You are not fighting." );
        }
        sb.append( CSConstantsString.NEWLINE );

        // --crafting status
        if ( getEntityController().isCrafting() ) {
            sb.append( "You are currently crafting: " + getEntityController().getCraftThread().getCraftController().getCraft().getCommand() + "." );
        }
        else {
            sb.append( "You are not currently crafting." );
        }
        sb.append( CSConstantsString.NEWLINE );

        // --settings
        // --pacifist?
        if ( getEntityController().isPacifist() ) {
            sb.append( "You are in pacifist mode." );
        }
        else {
            sb.append( "You'll fight back when attacked." );
        }
        sb.append( CSConstantsString.NEWLINE );
        // --accept give?
        if ( getEntityController().isAcceptGive() ) {
            sb.append( "You accept what others may try to give you." );
        }
        else {
            sb.append( "You won't accept items given by others." );
        }

        // --encumbrance
        sb.append( CSConstantsString.NEWLINE );
        sb.append( "Your weight allowance is " + getEntityController().getScoresController().getWeightCarry() + " grams." );

        getEntityController().tx( sb.toString() );

        return CommandExecutionResult.OK;
    }

    @Override
    public StatusInfo getInfo() {
        return (StatusInfo) super.getInfo();
    }

    @Override
    public boolean interruptsCrafting() {
        return false;
    }

}
